package com.monitor.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.monitor.entity.ErpAdvertisement;
import com.monitor.service.ErpAdvertisementService;
import com.monitor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 广告审核后表审核后表 前端控制器
 * </p>
 *
 * @author LX
 * @since 2018-09-25
 */
@RestController
@RequestMapping("/controller/erpAdvertisement")
@Api(description="广告审核后表")
public class ErpAdvertisementController {

    @Resource
    private ErpAdvertisementService advertisementService;

    @RequestMapping("/inertOrUpdatecheck")
    @ApiOperation("添加Or修广告审核后表表")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<Integer> inertOrUpdateInsurance(ErpAdvertisement insurance) {
        Result<Integer> result=new Result<Integer>();
        try{
        	insurance.setCheckState("0");
            result.setCount(1);
            result.setData(advertisementService.insertOrUpdate(insurance)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getcheckById")
    @ApiOperation("根据id查看广告审核后表信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "webId", value = "广告审核后表ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<ErpAdvertisement> getInsuranceById(Integer webId) {
        Result<ErpAdvertisement> result=new Result<ErpAdvertisement>();
        try{
            result.setCount(1);
            result.setData(advertisementService.selectById(webId));
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getcheckPage")
    @ApiOperation("查询广告审核后表分页")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<Page<ErpAdvertisement>> getUserBycustIdPage(@RequestParam(value = "page", defaultValue = "1") int page,
                                                            @RequestParam(value="limit",defaultValue="10") int limit,String cs) {
        Result<Page<ErpAdvertisement>> result=new Result<Page<ErpAdvertisement>>();
        try{
            Page<ErpAdvertisement> page1=new Page<ErpAdvertisement>(page,limit);
            Page<ErpAdvertisement> carPage=advertisementService.selectPage(page1,new EntityWrapper<ErpAdvertisement>().like("content",cs));
            //Page<ErpCustomerCar> page=new Page<ErpCustomerCar>(1,2);
            result.setCount(carPage.getRecords().size());
            result.setData(carPage);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }
    @RequestMapping("/getcheckPage2")
    @ApiOperation("查询广告审核完毕后表分页")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<Page<ErpAdvertisement>> getUserBycustIdPage2(@RequestParam(value = "page", defaultValue = "1") int page,
                                                            @RequestParam(value="limit",defaultValue="10") int limit) {
        Result<Page<ErpAdvertisement>> result=new Result<Page<ErpAdvertisement>>();
        try{
            Page<ErpAdvertisement> page1=new Page<ErpAdvertisement>(page,limit);
            Page<ErpAdvertisement> carPage=advertisementService.selectPage(page1,new EntityWrapper<ErpAdvertisement>().eq("check_state","1"));
            //Page<ErpCustomerCar> page=new Page<ErpCustomerCar>(1,2);
            result.setCount(carPage.getRecords().size());
            result.setData(carPage);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/removecheck")
    @ApiOperation("删除广告审核后表信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "webId", value = "广告审核后表ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<Integer> removeInsurance(Integer webId) {
        Result<Integer>  result=new Result<Integer>();
        try{

            result.setCount(1);
            result.setData(advertisementService.deleteById(webId)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/editShow")
    @ApiOperation("设置显示时长")
    @ApiImplicitParam(name = "min", value = "展示时长", required = false, dataType = "int", paramType = "query")
    public Result<Integer> editShow(int min){
    	return advertisementService.editShow(min);
    }

    @RequestMapping("/examine")
    @ApiOperation("广告审核")
    public Result<Integer> examine(int id,String time,String states,String name){
    	return advertisementService.examine(id, time, states, name);	
    }
}

